// 将数据同步存储到本地
export const setStorage = (key, data) => {
  wx.setStorageSync(key, data)
}

// 将数据异步存储到本地
export const asyncSetStorage = (key, data) => {
  return new Promise((resolve) => {
    wx.setStorage({
      key, data, complete(res) { resolve(res) }
    })
  })
}

// 从本地同步读取数据
export const getStorage = (key) => {
  return wx.getStorageSync(key)
}

// 从本地异步读取数据
export const asyncGetStorage = (key) => {
  return new Promise((resolve) => {
    wx.getStorage({
      key, complete(res) { resolve(res) }
    })
  })
}

// 从本地同步移除数据
export const removeStorage = (key) => {
  wx.removeStorageSync(key)
}

// 从本地异步移除数据
export const asyncRemoveStorage = (key) => {
  return new Promise((resolve) => {
    wx.removeStorage({
      key, complete(res) { resolve(res) }
    })
  })
}

// 同步清除本地全部数据
export const clearStorage = () => {
  wx.clearStorageSync()
}

// 异步清除本地全部数据
export const asyncClearStorage = () => {
  return new Promise((resolve) => {
    wx.clearStorage({
      complete(res) { resolve(res) }
    })
  })
}